using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using HengTong.Model.Db.SupplyChain.Material;
using WalkingTec.Mvvm.Core;

namespace HengTong.Model.Db.SupplyChain.Purchase;

/// <summary>
/// 采购申请单明细
/// </summary>
/// <remarks>
/// 记录采购申请单的具体物料明细信息，包括物料、数量、价格等详细内容
/// </remarks>
public class SysPurchaseRequestBillEntry : BasePoco
{
    #region 关联信息

    /// <summary>
    /// 获取或设置采购申请单
    /// </summary>
    /// <value>关联的采购申请单主表实体</value>
    [Display(Name = "采购申请单", Description = "关联的采购申请单主表", GroupName = "关联信息")]
    public SysPurchaseRequestBill Bill { get; set; }    
    
    /// <summary>
    /// 获取或设置采购申请单ID
    /// </summary>
    /// <value>关联的采购申请单主表ID</value>
    [Display(Name = "采购申请单ID", Description = "关联的采购申请单主表ID", GroupName = "关联信息")]
    public Guid? BillId { get; set; }
    
    #endregion

    #region 物料信息

    /// <summary>
    /// 获取或设置物料
    /// </summary>
    /// <value>采购的物料实体信息</value>
    [Display(Name = "物料", Description = "采购的物料", GroupName = "物料信息")]
    public SysMaterial Material { get; set; }
    
    /// <summary>
    /// 获取或设置物料ID
    /// </summary>
    /// <value>采购的物料ID</value>
    [Display(Name = "物料ID", Description = "采购的物料ID", GroupName = "物料信息")]
    public Guid? MaterialId { get; set; }
    
    /// <summary>
    /// 获取或设置物料SKU
    /// </summary>
    /// <value>采购的物料规格实体信息</value>
    [Display(Name = "物料规格", Description = "采购的物料规格", GroupName = "物料信息")]
    public SysMaterialSku MaterialSku { get; set; }
    
    /// <summary>
    /// 获取或设置物料SKU ID
    /// </summary>
    /// <value>采购的物料规格ID</value>
    [Display(Name = "物料规格ID", Description = "采购的物料规格ID", GroupName = "物料信息")]
    public Guid? MaterialSkuId { get; set; }
    
    /// <summary>
    /// 获取或设置是否备用物资
    /// </summary>
    /// <value>标识该物料是否为备用物资，备用物资不计入物料呆滞考核</value>
    /// <remarks>
    /// 当此字段为true时，该物料将被排除在呆滞物料统计和考核之外
    /// </remarks>
    [Display(Name = "是否备用物资", Description = "备用物资不计入物料呆滞考核", GroupName = "物料信息")]
    public bool IsBackupMaterial { get; set; }
    
    #endregion

    #region 数量和金额

    /// <summary>
    /// 获取或设置申请数量
    /// </summary>
    /// <value>物料的申请采购数量，精度为6位小数</value>
    [Display(Name = "申请数量", Description = "物料的申请采购数量", GroupName = "数量和金额")]
    [Column(TypeName = "decimal(18,6)")]
    public decimal RequestQuantity { get; set; }
    
    /// <summary>
    /// 获取或设置单位价格
    /// </summary>
    /// <value>物料的预估单价，精度为6位小数</value>
    [Display(Name = "单位价格", Description = "物料的预估单价", GroupName = "数量和金额")]
    [Column(TypeName = "decimal(18,6)")]
    public decimal UnitPrice { get; set; }
    
    /// <summary>
    /// 获取或设置总金额
    /// </summary>
    /// <value>明细行的总金额（数量×单价），精度为6位小数</value>
    [Display(Name = "总金额", Description = "明细行的总金额（数量×单价）", GroupName = "数量和金额")]
    [Column(TypeName = "decimal(18,6)")]
    public decimal TotalAmount { get; set; }
    
    /// <summary>
    /// 获取或设置预算金额
    /// </summary>
    /// <value>该物料的预算金额，精度为6位小数</value>
    [Display(Name = "预算金额", Description = "该物料的预算金额", GroupName = "数量和金额")]
    [Column(TypeName = "decimal(18,6)")]
    public decimal? BudgetAmount { get; set; }
    
    #endregion

    #region 技术要求
    
    /// <summary>
    /// 获取或设置技术要求
    /// </summary>
    /// <value>物料的技术规格和要求说明，最多1024个字符，超过500字建议上传技术文件</value>
    [Display(Name = "技术要求", Description = "物料的技术规格和要求说明，超过500字建议上传技术文件", GroupName = "技术要求")]
    [StringLength(1024, ErrorMessage = "技术要求不能超过1024个字符")]
    public string TechnicalRequirement { get; set; }
    
    #endregion

    #region 时间要求

    /// <summary>
    /// 获取或设置要求到货日期
    /// </summary>
    /// <value>该物料期望的到货日期</value>
    [Display(Name = "要求到货日期", Description = "该物料期望的到货日期", GroupName = "时间要求")] 
    public DateTime? RequiredArrivalDate { get; set; }

    #endregion

    #region 采购进度

    /// <summary>
    /// 获取或设置采购进度
    /// </summary>
    /// <value>该明细行的采购进度状态</value>
    /// <remarks>
    /// 跟踪单个物料的采购进度：审批中 → 需求池 → 采购中 → 运输中 → 已完成
    /// </remarks>
    [Display(Name = "采购进度", Description = "该明细行的采购进度状态", GroupName = "采购进度")]
    public PurchaseProgress? PurchaseProgress { get; set; }

    #endregion

    #region 附件信息

    /// <summary>
    /// 获取或设置附件列表
    /// </summary>
    /// <value>明细行关联的附件文件集合，如技术文件、图纸等</value>
    [Display(Name = "附件", Description = "明细行关联的附件文件，如技术文件、图纸等", GroupName = "附件信息")]
    public List<SysPurchaseRequestBillEntryFile> Files { get; set; }

    #endregion
}

/// <summary>
/// 采购进度枚举
/// </summary>
/// <remarks>
/// 定义采购申请单的处理进度状态，从审批到完成的全流程跟踪
/// </remarks>
public enum PurchaseProgress
{
    /// <summary>
    /// 采购审批中：采购申请正在审批流程中
    /// </summary>
    [Display(Name = "采购审批中")]
    采购审批中 = 0,

    /// <summary>
    /// 采购需求池：审批通过，进入采购需求池等待采购
    /// </summary>
    [Display(Name = "采购需求池")]
    采购需求池 = 1,

    /// <summary>
    /// 采购中：正在进行采购（询价、比价、下单等）
    /// </summary>
    [Display(Name = "采购中")]
    采购中 = 2,
    
    /// <summary>
    /// 运输中：已下单，物料正在运输途中
    /// </summary>
    [Display(Name = "运输中")]
    运输中 = 3,
    
    /// <summary>
    /// 已完成：物料已到货，采购流程完成
    /// </summary>
    [Display(Name = "已完成")]
    已完成 = 4,
    
    /// <summary>
    /// 已取消：采购申请已取消
    /// </summary>
    [Display(Name = "已取消")]
    已取消 = 9
}
